package com.zkthink.ceres.applet.notice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zkthink.base.R;
import com.zkthink.ceres.applet.authority.domain.entity.AppletMember;
import com.zkthink.ceres.applet.authority.mapper.AppletMemberMapper;
import com.zkthink.ceres.applet.notice.domain.vo.NoticePageVo;
import com.zkthink.ceres.member.dao.MemberMapper;
import com.zkthink.ceres.member.entity.Member;
import com.zkthink.context.BaseContextHandler;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import com.zkthink.ceres.applet.notice.mapper.AppletNoticeMapper;
import com.zkthink.ceres.applet.notice.domain.entry.AppletNotice;
import com.zkthink.ceres.applet.notice.service.AppletNoticeService;

/**
 * @Author cmz
 * @Date 2024-05-12 11:15
 */
@Service
public class AppletNoticeServiceImpl implements AppletNoticeService {

    @Resource
    private AppletNoticeMapper appletNoticeMapper;

    @Resource
    private MemberMapper memberMapper;


    @Override
    public R getMemberNotice(NoticePageVo noticePageVo) {
        Integer[] types = new Integer[2];
        types[0] = 1;
        Member member = memberMapper.selectById(BaseContextHandler.getUserId());
        if (member != null) {
            System.out.println(member);
            System.out.println(member.getRoleType());
            if (member.getRoleType() != null) {
                if (member.getRoleType() == 0) {
                    types[1] = 3;
                } else if (member.getRoleType() == 1) {
                    types[1] = 2;
                } else {
                    types[1] = 4;
                }
            }else{
                types[1] = 4;
            }
        }
        Page<AppletNotice> noticePage = new Page<>(noticePageVo.getPageNum(), noticePageVo.getPageSize());
        QueryWrapper<AppletNotice> noticeQueryWrapper = new QueryWrapper<>();
        noticeQueryWrapper.in("notice_type", types);

        Page<AppletNotice> appletNoticePage = appletNoticeMapper.selectPage(noticePage, noticeQueryWrapper);
        return R.success(appletNoticePage);
    }

}

